def n2c(x):
    return chr(ord('A')+x)

def work1(a,b,c,e,d): #
    if((a==0 or b==0)and a==4)or(a!=0 and b!=0):
        if((a==1 or b==1)and b==1)or(a!=1 and b!=1):
            if((a==2 or b==2)and e==0)or(a!=2 and b!=2):
                if((a==3 or b==3)and e!=2)or(a!=3 and b!=3):
                    if((a==4 or b==4)and a==3)or(a!=4 and b!=4):
                        return True
    return False

def work2(a,b,c,d,e): #
    if((a==0 or b==0)and a==4)or(a!=0 and b!=0 and a!=4):
        if((a==1 or b==1)and b==1)or(a!=1 and b!=1 and b!=1):
            if((a==2 or b==2)and e==0)or(a!=2 and b!=2 and e!=0):
                if((a==3 or b==3)and e!=2)or(a!=3 and b!=3 and e==2):
                    if((a==4 or b==4)and a==3)or(a!=4 and b!=4 and a!=3):
                        return True
    return False

def work(a=[]):
    pass

# tag = {}
def A(m,n,res=[]):
    if m<=0 :
        print res
        return
    for i in xrange(1,n+1):
        # if not tag.get(i) or tag[i]==0:
        if not i in res:
            # tag[i]=1
            res.append(i)
            A(m-1,n,res)
            res.pop()
            # tag[i]=0
def main():
    p = [True for i in xrange(5)]
    for a in xrange(5) :
        if p[a] :
            p[a] = False
            for b in xrange(5) :
                if p[b] :
                    p[b] = False
                    for c in xrange(5) :
                        if p[c] :
                            p[c] = False
                            for d in xrange(5) :
                                if p[d] :
                                    p[d] = False
                                    for e in xrange(5) :
                                        if p[e] :
                                            if work1(a,b,c,d,e):
                                                print n2c(a),n2c(b),n2c(c),n2c(d),n2c(e)
                                    p[d] = True
                            p[c] = True
                    p[b] = True
            p[a] = True

    print 'permutation:'
    m = int(input())
    n = int(input())
    A(m,n)

if __name__=='__main__' :
    main()
